<template>
	<view class="ljapp textpage">
		<view class="content">
			<view class="card" :class="item.status" v-for="(item,index) in group.list" :key="index">
				<view class="outer u-flex">
					<image class="avatar" :src="$base.img(item.user_headimgurl)" mode="aspectFill"></image>
					<view class="info u-flex-1">
						<view class="u-flex u-flex-between">
							<view v-if="item.user_the_patient_info">
								<text class="name">就诊人：{{item.user_the_patient_info.name}}</text>
								<text class="sex">{{item.user_the_patient_info.sex==1?'男':'女'}}</text>
								<text class="age">{{item.user_the_patient_info.age}}岁</text>
							</view>
							<view v-else>
								<text class="name">就诊人：--</text>
							</view>
						</view>
						<view class="time">时间：{{item.createtime}}</view>
						<view class="sn">订单号：{{item.order_code}}</view>
						<view class="con u-line-2">病情描述：{{item.content}}</view>
					</view>
					<view class="status">{{item.typename}}</view>
				</view>
				<view class="bottom u-flex u-flex-end">
					<view class="btn-capsule" @click="Onjump(item)">问诊记录</view>
				</view>
			</view>

			<lj-empty v-if="group.loaded&&group.list.length<=0">暂无订单</lj-empty>
			<view v-else>
				<u-loadmore
					:status="loading?'loading':(group.loaded?'nomore':'loadmore')"
					fontSize="28rpx"
					color="#d9d9d9"
					nomoreText="已加载全部"
					marginTop="30rpx"
					marginBottom="0"
					@loadmore="getList"
				></u-loadmore>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				funnel: 0,
				
				group:{
					page: 1,
					limit: 10,
					list: [],
					loaded: false
				},
				loading: false,
			}
		},
		onLoad(options){
			if(options.funnel) this.funnel = options.funnel
			this.init()
		},
		methods: {
			init(){
				this.group.page = 1
				this.group.list = []
				this.group.loaded = false
				this.loading = false

				this.getList();
			},
			getList() {
				var that = this,group = that.group;
				if(that.loading || group.loaded) return;

				that.loading = true

				this.$Http({
					url: 'doctorlistConsultationVideoOrder',
					data: {
						page: group.page,
						limit: group.limit,
						funnel: this.funnel,
					},
					type:'POST',
				}).then(res=>{
					if(res.code == 1){
						var list = res.data.data;
						group.loaded = list.length < group.limit;
						group.page ++;

						list.forEach(item => {
							item.createtime = this.$base.formatTime(new Date(item.createtime *
								1000), "yyyy.MM.dd hh:mm:ss")
							if(item.user_the_patient_info) item.user_the_patient_info.age = this.$base.Onage(item.user_the_patient_info.birthday)

							if (item.pay_status == 2) {
								if (item.status == 'normal') {
									item.typename = '待支付'
								}
								if (item.status == 'cancel') {
									item.typename = '已取消'
								}
								item.status_is = false
							}
							if (item.pay_status == 1) {
								item.status_is = true
								if (item.status == 'normal') {
									item.typename = '待接诊'
								}
								if (item.status == 'refund') {
									item.typename = '已退款'
									item.status_is = false
								}
								if (item.status == 'refuse_patient') {
									item.typename = '拒绝接诊'
								}
								if (item.status == 'patient') {
									item.typename = '接诊中'
								}
								if (item.status == 'end') {
									item.typename = '接诊完成'
								}
								if (item.status == 'comment') {
									item.typename = '已评价'
								}
							}
						})

						group.list = group.list.concat(list);
					}

					that.loading = false
				}).catch(()=>{
					that.loading = false
				});
			},
			onReachBottom(){
				this.getList()
			},


			//详情
			Ontextinfo(e) {
				uni.navigateTo({
					url: '/pagesA/doctor/textinfo?id=' + e.id + '&type=sp',
				})
			},
			//操作
			Ontrue(obj, type) {
				let that = this
				let url = ''
				let content = ''
				if (type == 'confirm') {
					content = '您确定要接诊吗'
					url = 'consultationVideoPatient'
				}
				if (type == 'refuse') {
					content = '您确定要拒绝接诊吗'
					url = 'consultationVideoRefusePatient'
				}
				if (type == 'end') {
					content = '您确定要完成接诊吗'
					url = 'videoEndPatient'
				}

				uni.showModal({
					title: '操作提示',
					confirmText: '确定',
					confirmColor: '#b8875c',
					cancelText: '取消',
					content: content,
					success: function(res) {
						if (res.confirm) {
							that.$Http({
								url: url,
								data: {
									order_id: obj.id
								},
								type: 'POST',
							}).then(res => {
								if (res.code == 1) {
									that.$refs.LoadMore.oncutRefresh(that.initData)
								}
							});
						}
					}
				});
			},
			Onjump(e) {
				uni.navigateTo({
					// url: '/pagesA/common/video?id=' + e.id + '&type=doc',
					url: '/pagesA/message/chat?isDoc=1&cate=video&orderno='+e.order_code
				})
			}
		}
	}
</script>


<style lang="less">
	@import '@/pagesD/style.less';
</style>
